package com.seal.tsms.exam.controller;

import com.seal.tsms.base.controller.BaseController;
import com.seal.tsms.base.service.BaseService;
import com.seal.tsms.exam.entity.Profession;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;

import java.util.List;

/**
 * Created by Administrator on 2016/6/6.
 */
@Controller
@RequestMapping("/profession")
public class ProfessionController extends BaseController<Profession,String> {
    @Override
    @Autowired
    @Qualifier("professionServiceImpl")
    public void setSelfService(BaseService<Profession, String> selfService) {
        super.setSelfService(selfService);
    }

    @RequestMapping(value = "/save",method = RequestMethod.GET)
    public String create(){
        return "exam/profession/add";
    }
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public String save(Profession profession, RedirectAttributesModelMap model){
        getSelfService().save(profession);
        model.addFlashAttribute("msg","成功保存一条数据");

        return "redirect:list.action";
    }

    @RequestMapping(value = "/list")
    public String list(ModelMap model){
        List<Profession> professions= (List<Profession>) getSelfService().list(DetachedCriteria.forClass(Profession.class),null);
       model.addAttribute("professions",professions);
        return "exam/profession/list";
    }
    @RequestMapping(value = "professionListAjax")
    @ResponseBody
    public List<Profession> ajaxList(){
        return (List<Profession>) getSelfService().list(DetachedCriteria.forClass(Profession.class),null);
    }


}
